<html>
<head><meta charset="utf-8"><title>procedural macro on expression · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/procedural.20macro.20on.20expression.html">procedural macro on expression</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="226297536"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/procedural%20macro%20on%20expression/near/226297536" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kentrixy <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/procedural.20macro.20on.20expression.html#226297536">(Feb 14 2021 at 10:30)</a>:</h4>
<p>Any idea/RFC for procedural macro on expressions? For example:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">example</span><span class="p">(</span><span class="n">v</span>: <span class="kt">i32</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">  </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span><span class="w"></span>
<span class="w">  </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">counter</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span><span class="w"></span>
<span class="w">  </span><span class="cp">#[invariant(...)]</span><span class="w"></span>
<span class="w">  </span><span class="k">while</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">&lt;</span><span class="w"> </span><span class="n">v</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">i</span><span class="w"> </span><span class="o">+=</span><span class="w"> </span><span class="mi">1</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="n">counter</span><span class="w"> </span><span class="o">+=</span><span class="w"> </span><span class="n">i</span><span class="p">;</span><span class="w"></span>
<span class="w">  </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="226297603"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/procedural%20macro%20on%20expression/near/226297603" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kentrixy <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/procedural.20macro.20on.20expression.html#226297603">(Feb 14 2021 at 10:32)</a>:</h4>
<p>To do something like above right now, have to resort to <code>macro_rules!</code></p>



<a name="226310151"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/procedural%20macro%20on%20expression/near/226310151" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/procedural.20macro.20on.20expression.html#226310151">(Feb 14 2021 at 15:39)</a>:</h4>
<p>I think the discussion is here: <a href="https://github.com/rust-lang/rust/issues/15701">https://github.com/rust-lang/rust/issues/15701</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>